﻿using System;
using System.Collections.Generic;

namespace ConsoleApp22
{
    class Program
    {
        static void Main(string[] args)
        {
            ObjectStructure o2 = new ObjectStructure();
            o2.Attach(new Man());
            o2.Attach(new Woman());

            Success v1 = new Success();
            o2.Display(v1);


            Console.Read();
        }
    }


    abstract class Action
    {
        public abstract void GetManConclusion(Man concreteElementA);

        public abstract void GetWomanConclusion(Woman concreteElementB);
    }
    abstract class Person
    {
        public abstract void Accept(Action visitor);
    }

    class Success : Action
    {
        public override void GetManConclusion(Man concreteElementA)
        {
            Console.WriteLine("{0}  {1},时，背后多半有一个伟大的女人!", concreteElementA.GetType().Name, this.GetType().Name);
        }

        public override void GetWomanConclusion(Woman concreteElementB)
        {
            Console.WriteLine("{0}  {1},时，背后多半有一个不成功的男人!", concreteElementB.GetType().Name, this.GetType().Name);
        }
    }
    class Man : Person
    {
        public override void Accept(Action visitor)
        {
            visitor.GetManConclusion(this);
        }
    }
    class Woman : Person
    {
        public override void Accept(Action visitor)
        {
            visitor.GetWomanConclusion(this);
        }
    }

    class ObjectStructure
    {
        private IList<Person> elements = new List<Person>();

        public void Attach(Person element)
        {
            elements.Add(element);
        }

        public void Display(Action visitor)
        {
            foreach (Person e in elements)
            {
                e.Accept(visitor);
            }
        }
    }


}
